<?php

if(isset($_POST["logIn"]))
{
	$loginError = User::checkUserNameAndPassword($_POST["user_name"], md5($_POST["password"]));
	if($loginError !== true)
	{
		echo "<font-color='#ff0000'>".$loginError."</font>";
	}
	else
	{
		
		$user = new User($_POST["user_name"]);
		$_SESSION["user"] = $user;
	}
}

if(!isset($_SESSION["user"]))
{
?>

<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" >
	<p>Потребителско име:</p>
	<input type="text" name="user_name" />
	<p>Парола:</p>
	<input type="password" name="password" />
	<input type="submit" name="logIn" value="Вход" />
</form>
<a href="?view=register">Регистрирай се</a>
<?php
}
else
{
	$user = $_SESSION["user"];
	echo "Добре дошъл " . $user->getUser_name() . "<br />";
	echo "Уникалният ви код е: " . $user->getUser_id() . "<br />";
	echo "Email: " . $user->getEmail() . "<br />";
	echo "Роден сте на: " . $user->getBorn_date() . "<br />";
	echo "Пол " . $user->getGender() . "<br />";
	echo "Регистрирали сте се на " . $user->getRegister_date() . "<br />";
	echo "<a href='?view=insertContent'>Добавете публикация</a><br />";
	
	echo "<a href=\"logout.php\"><button>Излез</button></a>";
}
?>